package com.register;

import cn.hutool.core.util.URLUtil;
import com.register.client.model.RegisterInfo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@SpringBootApplication
@RestController
public class RegisterApplication {

    private static Map<String,RegisterInfo> map = new ConcurrentHashMap<>();

    public static void main(String[] args) {
        SpringApplication.run(RegisterApplication.class);
    }


    @RequestMapping("/register")
    public String register(@RequestBody RegisterInfo registerInfo){
        map.put(registerInfo.getApiName(), registerInfo);
        return "success";
    }

    @RequestMapping("/getApiInfo")
    public RegisterInfo getApiInfo(@RequestBody String apiName){
        apiName = URLUtil.decode(apiName);
        if(apiName.endsWith("=")){
            apiName = apiName.replace("=", "");
        }
        return map.get(apiName);
    }

}
